/*
 * Copyright (c) 2022-2023 cetcclout Co., Ltd All rights reserved.
 * Sensor Adapter is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package com.cetccloud.cimp.adapter.handler.netty;

import com.cetccloud.cimp.adapter.handler.abstracts.AbstractParserHandler;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.nio.Buffer;

/**
 * @author
 * @apiNote 报文数据转换
 * @date 2023/1/6 11:00
 */
@Component("tcpParserHandler")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class TcpParserHandler extends AbstractParserHandler {
    private final static InternalLogger logger = InternalLoggerFactory.getInstance(TcpParserHandler.class);

    /**
     * 初始化报文转换配置
     */
    @Override
    public void init(String tableName) {
    	logger.info("当前服务配置");
    }
    
    /**
     * 设备报文转换为系统报文
     */
    @Override
    public Buffer unpack(Buffer buffer, String dtuId) {
        String data = new String((byte[]) buffer.array());
        logger.info("根据数据协议解析报文数据：{}", data);
        this.dataType = "ENV_DATA";
        return buffer;
    }

    /**
     * 系统报文转换为设备报文
     */
    @Override
    public Buffer pack(Buffer buffer, String dtuId) {
        return null;
    }
}
